package com.yyge.mapper;

import com.yyge.controller.admin.product.req.ProductAddReq;
import com.yyge.controller.admin.product.req.ProductReq;
import com.yyge.controller.admin.product.resp.ProductResp;
import com.yyge.entity.Product;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
* @author Administrator
* @description 针对表【product(商品信息)】的数据库操作Mapper
* @createDate 2023-07-02 20:36:22
* @Entity com.yyge.entity.Product
*/
@Mapper
public interface ProductMapper extends BaseMapper<Product> {

    List<ProductResp> search(@Param(value = "req") ProductReq req);
    List<ProductResp> addSearch(@Param(value = "req") ProductAddReq req);

    /**
     * 根据主键查询数据（悲观锁）
     * @param dishId
     * @return
     */
    Product pessimisticLockById(Long dishId);

    /**
     * 减库存
     * @param dishId
     * @param n
     * @return
     */
    @Update(value = "update product set num=num-#{n} where id=#{dishId}")
    int  descNum(@Param(value = "dishId") Long dishId, @Param(value = "n")int n);

    List<ProductResp> searchById(@Param(value = "req") ProductReq req,@Param(value = "key") String key);
}





